package thinkinjava4.ch21_concurrency;

import java.util.concurrent.*;

public class CachedThreadPool {
    /**
     * 核心线程池的大小
     */
    private static final int CORE_POOL_SIZE = 5;
    /**
     * 线程池最大能创建的线程数目大小
     */
    private static final int MAXIMUM_POOL_SIZE = 5;
    /**
     * 线程存活时间
     */
    private static final long KEEP_ALIVE_TIME = 0L;

    public static void main(String[] args) {
        //使用线程池创建线程
        ExecutorService singleThreadPool = new ThreadPoolExecutor(
                CORE_POOL_SIZE,
                MAXIMUM_POOL_SIZE,
                KEEP_ALIVE_TIME,
                TimeUnit.MILLISECONDS,
                new LinkedBlockingDeque<>(5));
        ExecutorService exec = Executors.newCachedThreadPool();
        for (int i = 0; i < 5; i++)
            exec.execute(new LiftOff());
        exec.shutdown();
//        for (int i = 0; i < 5; i++)
//            singleThreadPool.execute(new LiftOff());
//        singleThreadPool.shutdown();
    }
}
